﻿/* --------------------------------------------------------------
 * exMath (C) Laurens Ruijtenberg
 * 
 * This code is being distributed under the MS-PL license. Feel
 * free to contact me if you like this code.
 * -------------------------------------------------------------- */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace exMath.Common
{
    public class MathUtilities
    {
        public static int LowestCommonDenominator(int x, int y)
        {
            int denominator;
            int min = x > y ? x : y;

            for (denominator = 2; denominator < min; denominator++)
            {
                if ((x % denominator == 0) && (y % denominator == 0))
                    break;
            }

            return denominator;
        }

        public static int GreatesCommonDevider(int x, int y)
        {
            return ((x * y) / LowestCommonMultiple(x, y));
        }

        public static int LowestCommonMultiple(int x, int y)
        {
            int n;

            for (n = 1; ; n++)
            {
                if (n % x == 0 && n % y == 0)
                    return n;
            }
        }
    }
}
